home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Include / FWGrObj.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  5.7 KB  |  187 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWGrObj.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWGROBJ_H
  11. #define FWGROBJ_H
  12.  
  13. #ifndef FWSTREAM_H
  14. #include "FWStream.h"
  15. #endif
  16.  
  17. // ----- Foundation Includes -----
  18.  
  19. #ifndef FWSTDDEF_H
  20. #include "FWStdDef.h"
  21. #endif
  22.  
  23. #ifndef FWCLAINF_H
  24. #include "FWClaInf.h"
  25. #endif
  26.  
  27. #ifndef FWAUTODE_H
  28. #include "FWAutoDe.h"
  29. #endif
  30.  
  31. #if FW_LIB_EXPORT_PRAGMAS
  32. #pragma lib_export on
  33. #endif
  34.  
  35. //========================================================================================
  36. //    Forward Declaration
  37. //========================================================================================
  38.  
  39. class FW_CLASS_ATTR FW_CGraphicCountedPtrRep;
  40. class FW_CLASS_ATTR FW_CGraphicCountedPtr;
  41.  
  42. //========================================================================================
  43. //    Global operators << and >>
  44. //========================================================================================
  45.  
  46. FW_FUNC_ATTR FW_CReadableStream& operator>>(FW_CReadableStream& archive, FW_CGraphicCountedPtr &object);
  47. FW_FUNC_ATTR FW_CWritableStream& operator<<(FW_CWritableStream& archive, const FW_CGraphicCountedPtr &object);
  48.  
  49. //========================================================================================
  50. //    CLASS FW_CGraphicCountedPtr
  51. //========================================================================================
  52.  
  53. class FW_CLASS_ATTR FW_CGraphicCountedPtr FW_AUTO_DESTRUCT_OBJECT
  54. {
  55.     friend FW_CReadableStream& operator>>(FW_CReadableStream&, FW_CGraphicCountedPtr&);
  56.     friend FW_CWritableStream& operator<<(FW_CWritableStream&, const FW_CGraphicCountedPtr&);
  57.     
  58. public:
  59.     FW_DECLARE_CLASS
  60.  
  61. public:
  62.     FW_CGraphicCountedPtr();
  63.         // Creates a "NULL" pointer.
  64.  
  65.     FW_CGraphicCountedPtr(const FW_CGraphicCountedPtr& other);
  66.  
  67.     virtual ~ FW_CGraphicCountedPtr();
  68.         // Destroy the pointer.  
  69.         // Decrements the count in the rep, and deletes the rep if count is zero.
  70.  
  71.     FW_Boolean operator==(const FW_CGraphicCountedPtr& other) const;
  72.     FW_Boolean operator!=(const FW_CGraphicCountedPtr& other) const;
  73.  
  74.     operator const void*() const;
  75.         // Use to test if this is a "NULL" pointer.
  76.         
  77.     FW_Boolean            IsSameRepAs(const FW_CGraphicCountedPtr& p) const;
  78.  
  79. protected:    
  80.     void UpCount();
  81.         // Implementation method, increment the reference count in rep.
  82.         
  83.     void DownCount();
  84.         // Implementation method, decrement the reference count in rep.
  85.         // Deletes rep if reference count is zero.
  86.     
  87.     FW_CGraphicCountedPtrRep*     GetRep() const
  88.                                     {return fRep;}
  89.     void                        SetRep(FW_CGraphicCountedPtrRep* rep);
  90.     
  91. private:    
  92.     FW_CGraphicCountedPtrRep *fRep;
  93. };
  94.  
  95. //========================================================================================
  96. //    class FW_CGraphicCountedPtrRep
  97. //========================================================================================
  98.  
  99. class FW_CLASS_ATTR FW_CGraphicCountedPtrRep
  100. {
  101.     friend class FW_CLASS_ATTR FW_CGraphicCountedPtr;
  102.     
  103. public:
  104.     FW_DECLARE_CLASS
  105.  
  106. //----------------------------------------------------------------------------------------
  107. //    Constructors/Destructors
  108. //
  109.  
  110. public:    
  111.     FW_CGraphicCountedPtrRep();
  112.     virtual ~FW_CGraphicCountedPtrRep();
  113.  
  114. private:
  115.     FW_CGraphicCountedPtrRep(const FW_CGraphicCountedPtrRep& otherRep);
  116.     FW_CGraphicCountedPtrRep& operator=(const FW_CGraphicCountedPtrRep& otherRep) const;
  117.     
  118. //----------------------------------------------------------------------------------------
  119. //    New API
  120. //
  121. public:
  122.     unsigned long            GetRefCount() const
  123.                                 {return fRefCount;}
  124.  
  125.     virtual void            Purge();
  126.     
  127.     virtual void            Flatten(FW_CWritableStream& archive) const = 0;
  128.  
  129.     virtual FW_Boolean        IsEqual(const FW_CGraphicCountedPtrRep* other) const = 0;
  130.     
  131.     static void             Write(FW_CWritableStream& archive, const void* Rep);
  132.     
  133. protected:
  134.     void                    IncrementRefCount()
  135.                                 {fRefCount++;}
  136.     unsigned long            Release()
  137.                                 {return --fRefCount;}
  138.                             
  139. //----------------------------------------------------------------------------------------
  140. //    Data Members
  141. //
  142. private:
  143.     unsigned long            fRefCount;
  144. };
  145.  
  146. //========================================================================================
  147. //    Inlines
  148. //========================================================================================
  149.  
  150. //----------------------------------------------------------------------------------------
  151. // FW_CGraphicCountedPtr::operator==
  152. //----------------------------------------------------------------------------------------
  153. inline FW_Boolean FW_CGraphicCountedPtr::IsSameRepAs(const FW_CGraphicCountedPtr& p) const
  154. {
  155.     return fRep == p.fRep;
  156. }
  157.  
  158. //----------------------------------------------------------------------------------------
  159. // FW_CGraphicCountedPtr::operator==
  160. //----------------------------------------------------------------------------------------
  161. inline FW_Boolean FW_CGraphicCountedPtr::operator==(const FW_CGraphicCountedPtr& other) const
  162. {
  163.     return fRep->IsEqual(other.fRep);
  164. }
  165.  
  166. //----------------------------------------------------------------------------------------
  167. //    FW_CGraphicCountedPtr::operator!=
  168. //----------------------------------------------------------------------------------------
  169. inline FW_Boolean FW_CGraphicCountedPtr::operator!=(const FW_CGraphicCountedPtr& other) const
  170. {
  171.     return !fRep->IsEqual(other.fRep);
  172. }
  173.  
  174. //----------------------------------------------------------------------------------------
  175. //    FW_CGraphicCountedPtr::operator const void*
  176. //----------------------------------------------------------------------------------------
  177. inline FW_CGraphicCountedPtr::operator const void*() const
  178. {
  179.     return (const void*) fRep;
  180. }
  181.  
  182. #if FW_LIB_EXPORT_PRAGMAS
  183. #pragma lib_export off
  184. #endif
  185.  
  186. #endif
  187.